import { UnifiedViteWeappTailwindcssPlugin } from 'weapp-tailwindcss/vite'
import tailwindcss from '@tailwindcss/postcss'
import path from 'node:path'
import { defineConfig } from '@tarojs/cli'
import devConfig from './dev'
import prodConfig from './prod'

export default defineConfig(async (merge, { command, mode }) => {
  const baseConfig = {
    projectName: 'client',
    date: '2025-11-7',
    designWidth: 750,
    deviceRatio: { 640: 2.34 / 2, 750: 1, 375: 2, 828: 1.81 / 2 },
    sourceRoot: 'src',
    outputRoot: 'build',
    plugins: ['@taro-hooks/plugin-react', '@tarojs/plugin-html'],
    defineConstants: {},
    copy: { patterns: [], options: {} },
    framework: 'react',
    alias: { '@/components': path.resolve(__dirname, '..', 'src/components'), '@/utils': path.resolve(__dirname, '..', 'src/utils'), '@/assets': path.resolve(__dirname, '..', 'src/assets') },
    compiler: { type: 'vite', vitePlugins: [{ name: 'postcss-config-loader-plugin', config(config) { if (typeof config.css?.postcss === 'object') { config.css?.postcss.plugins?.unshift(tailwindcss()) } }, }, UnifiedViteWeappTailwindcssPlugin({ rem2rpx: true, cssEntries: [path.resolve(__dirname, '../src/app.css'),], }),] },
    mini: { postcss: { pxtransform: { enable: true, config: {} }, cssModules: { enable: false, config: { namingPattern: 'module', generateScopedName: '[name]__[local]___[hash:base64:5]' } } } },
    h5: { esnextModules: ['taro-ui'], publicPath: '/', staticDirectory: 'static', miniCssExtractPluginOption: { ignoreOrder: true, filename: 'css/[name].[hash].css', chunkFilename: 'css/[name].[chunkhash].css' }, postcss: { autoprefixer: { enable: true, config: {} }, cssModules: { enable: false, config: { namingPattern: 'module', generateScopedName: '[name]__[local]___[hash:base64:5]' } } } },
    rn: { appName: 'taroDemo', postcss: { cssModules: { enable: false, } } }
  }
  if (process.env.NODE_ENV === 'development') { return merge({}, baseConfig, devConfig) }
  return merge({}, baseConfig, prodConfig)
})
